package com.softeem.music.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.softeem.music.comm.R;
import com.softeem.music.entity.Admin;
import com.softeem.music.service.AdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "管理员管理模块")
@RestController
public class AdminController {

    @Autowired
    private AdminService adminService;

    @Operation(summary = "管理员列表", description = "分页查询所有管理员")
    @Parameters({
            @Parameter(name = "page", description = "页码"),
            @Parameter(name = "limit", description = "数据条数")
    })
    @GetMapping("/admin/list")
    public R list(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "6") Integer limit) {
        IPage<Admin> iPage = new Page<>(page,limit);
        return R.success().setData(adminService.list(iPage));
    }

    @Operation(summary = "添加管理员", description = "添加管理员")

    @PostMapping("/admin/add")
    public R add(Admin admin) {
        return adminService.add(admin);
    }

    //http请求方法分类增加:post 删除:delete 修改:update查询:get

    @Operation(summary = "修改管理员", description = "根据id修改管理员")
    @PutMapping("/admin/update")
    public boolean update(@RequestBody Admin admin) {return adminService.updateById(admin);}



    @Operation(summary = "删除管理员", description = "根据id删除管理员")
    @Parameters({
            @Parameter(name = "id", description = "管理员id")
    })
    @DeleteMapping("/admin/delete")
    public boolean delete(int id) {
        return adminService.removeById(id);}


    @Operation(summary="管理员登录",description ="根据用户名和密码登录")
    @Parameters({
            @Parameter(name ="username",description="用户名"),
            @Parameter(name ="password",description="密码")
    })

    /*@RequestMapping("/admin/select")
    public List<Admin> select(Admin admin) {
        return adminService.list(new QueryWrapper<>(admin));
    }*/

    @GetMapping("/admin/login")
    public R login(String username, String password){
        //todo 实现管理员登录逻辑
        return adminService.login(username,password);
    }



}
